package com.ewzj.bigdata.mvp.model;

import android.app.Application;

import com.ewzj.bigdata.app.utils.Apputils;
import com.ewzj.bigdata.mvp.model.api.Api;
import com.ewzj.bigdata.mvp.model.api.service.CommonService;
import com.ewzj.bigdata.mvp.model.entity.reqbeans.ReqMobile;
import com.ewzj.bigdata.mvp.model.entity.reqbeans.ReqRegister;
import com.ewzj.bigdata.mvp.model.entity.resbean.BaseData;
import com.ewzj.bigdata.mvp.model.entity.resbean.BaseJson;
import com.google.gson.Gson;
import com.jess.arms.base.App;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.ewzj.bigdata.mvp.contract.RegisterContract;

import io.reactivex.Observable;


@ActivityScope
public class RegisterModel extends BaseModel implements RegisterContract.Model {
    private Gson mGson;
    private Application mApplication;
    private CommonService service;
    @Inject
    public RegisterModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
        super(repositoryManager);
        this.mGson = gson;
        this.mApplication = application;
        this.service=repositoryManager.obtainRetrofitService(CommonService.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseData<String>> sendSms(String password) {
        ReqMobile reqMobile=new ReqMobile(password);
        return service.sendSms(Apputils.json2Body(mGson.toJson(reqMobile)));
    }

    @Override
    public Observable<BaseData<String>> register(String user, String pwd, String code) {
        ReqRegister reqRegister=new ReqRegister(user,pwd,code);
        return service.registerUser(Apputils.json2Body(mGson.toJson(reqRegister)));
    }
}